#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

class Solution
{
private:
    vector<int> tmp;
    vector<vector<int>> ans;

public:
    vector<vector<int>> permuteUnique(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        vector<bool> used(nums.size(), false);
        Helper(nums,used);
        return ans;
    }
    
    void Helper(const vector<int> &nums, vector<bool> &used)
    {
       
        if (tmp.size() == nums.size())
        {
            ans.push_back(vector<int>(tmp));
            return;
        }

        for (int i = 0; i < nums.size(); i++)
        {
            if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1])
            {
                continue;
            }
            if(used[i]){
                continue;
            }
            tmp.push_back(nums[i]);
            used[i] = true;
            Helper(nums, used);
            used[i] = false;
            tmp.pop_back();
        }
    }
};

int main()
{
    Solution solu = Solution();
    vector<int> input = {1, 1, 2};
    solu.permuteUnique(input);
    int i = 1;
    return 0;
}